package com.touwowo.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.touwowo.utils.RabbitMqUtils;

public class ReceiveLogsDirect02 {
    //申明交换机名称
    private static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        String queue = channel.queueDeclare().getQueue();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        channel.queueBind(queue,EXCHANGE_NAME,"error");

        DeliverCallback callback = (consumerTag, message) -> {
            System.out.println("收到的消息为："+new String(message.getBody()));
        };

        channel.basicConsume(queue,false,callback,consumerTag -> {});
    }
}
